package com.briup.mt.web.controller;

import com.briup.mt.service.ICategoryService;
import com.briup.mt.bean.Category;
import com.briup.mt.utils.Message;
import com.briup.mt.utils.MessageUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("/category")
@Validated
public class CategoryController {
    @Autowired
    private ICategoryService categoryService;

    @GetMapping("query")
    public Message query(String name){
        List<Category>list=categoryService.query(name);
        return MessageUtil.success(list);
    }
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Category category){
        categoryService.saveOrUpdate(category);
        return  MessageUtil.success("保存成功");
    }
    @DeleteMapping("deleteById")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value="评论编号",required = true,paramType = "query")
    })
    public Message deleById(@NotNull long id){
        categoryService.deleteById(id);
        return MessageUtil.success("删除成功");
    }
}
